#!/usr/bin/python

# python-resmon - Python tools for Resmon monitoring and the Circonus API
# Copyright (c) 2010 Crown coypright
# 
# This file is part of python-resmon.
# 
# python-resmon is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# python-resmon is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with python-resmon.  If not, see <http://www.gnu.org/licenses/>.


import yaml

from circonus.api import CirconusAPI
from circonus.sync import *

URL_FOR_NODE = aggregator_url_for_node

if __name__ == '__main__':
    from optparse import OptionParser
    parser = OptionParser()
    parser.add_option('-n', '--no-act', action="store_true", help="Don't update Circonus; just print what would be done")
    parser.add_option('-g', '--generate', action="store_true", help="Stop after generating the model")
    parser.add_option('-l', '--load', help="Load metrics from rules file")
    parser.add_option('-d', '--debug', action="store_true", help="Print requests to Circonus")

    options, args = parser.parse_args()

    if not options.load:
        parser.error("You must provide a rules file to load (-l)")

    model = load_model(options.load, url_for_node=URL_FOR_NODE)
    yaml.dump(model, open('model.yaml', 'wb'))

    circonus_account = CirconusAPI.from_config(debug=options.debug)
    if args:
        hosts = args
    else:
        hosts = None
    sync_model_to_circonus(circonus_account, model, hosts=hosts, no_act=options.no_act)

